#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N],c[N];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    scanf("%d",&t);
    while(t--){
        memset(a,0,sizeof(a));
        memset(c,0,sizeof(c));
        int n,x,e=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d",&x);
            a[x]++;
            if(a[x]==1) c[e++]=x;
        }
        int ans=0;
        for(int i=0;i<e;i++){
 //           cout<<c[i]<<" "<<a[c[i]]<<endl;
            if(a[c[i]]>=2){
                ans+=c[i]*(a[c[i]]-1);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
